package com.wjr.braveheart.dao;

import com.wjr.braveheart.db.CacheUtils;

/**
 * @Description: 数据缓存
 * //TODO: 删除和清空(暂未实现）
 * @Author: 作者名
 * @Email: 邮箱
 * @CreateDate: 2020/6/8 10:47
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 * PS: You can change the world with code! Don't give up!
 */
public class CacheIOHandler implements IOHandler {
    @Override
    public void save(String key, String value) {
        CacheUtils.cacheJson(key, value);
    }

    @Override
    public void save(String key, double value) {
        CacheUtils.cacheJson(key, String.valueOf(value));
    }

    @Override
    public void save(String key, int value) {
        CacheUtils.cacheJson(key, String.valueOf(value));
    }

    @Override
    public void save(String key, long value) {
        CacheUtils.cacheJson(key, String.valueOf(value));
    }

    @Override
    public void save(String key, boolean value) {
        CacheUtils.cacheJson(key, String.valueOf(value));
    }

    @Override
    public void save(String key, Object value) {
        CacheUtils.cacheJson(key, String.valueOf(value));
    }

    @Override
    public String getString(String key) {
        return CacheUtils.getCacheJson(key);
    }

    @Override
    public double getDouble(String key, double defaultValue) {
        return Double.parseDouble(CacheUtils.getCacheJson(key));
    }

    @Override
    public int getInt(String key, int defaultValue) {
        return Integer.parseInt(CacheUtils.getCacheJson(key));
    }

    @Override
    public long getLong(String key, long defaultValue) {
        return Long.parseLong(CacheUtils.getCacheJson(key));
    }

    @Override
    public boolean getBoolean(String key, boolean defaultValue) {
        return Boolean.parseBoolean(CacheUtils.getCacheJson(key));
    }

    @Override
    public Object getObject(String key) {
        return CacheUtils.getCacheJson(key);
    }

    @Override
    public void delete(String key) {
        //TODO

    }

    @Override
    public void clear() {
        //TODO

    }
}
